try { // code . . . . . . } catch (ExceptionName err) { // Error Handling block } catch (ExceptionName err) { // Error Handling block } . . . . . . finally { statements... }
class demo { public static void main(String args[]) { System.out.println(" before call" ); test(8,2); System.out.println(" after call" ); System.out.println(" program end" ); } public static void test( int a , int b ) { int c=0; System.out.println("before expression..."); c= a/b; System.out.println("after expression"); System.out.println(" Result is :"+c ); } }
before call before expression... after expression Result is :4 after call program end
class demo { public static void main(String args[]) { System.out.println(" before call" ); test(8,0); System.out.println(" after call" ); System.out.println(" program end" ); } public static void test( int a , int b ) { int c=0; System.out.println("before expression..."); c= a/b; System.out.println("after expression"); System.out.println(" Result is :"+c ); } }
Before call Before expression Arithmetic Exception
class demo { public static void main(String args[]) { System.out.println(" before call" ); test(8,2); System.out.println(" after call" ); System.out.println(" program end" ); } public static void test( int a , int b ) { int c=0; try { System.out.println("before expression..."); c= a/b; System.out.println("after expression"); } catch(ArithmeticException er) { System.out.println("error message : "+er); c=1; } System.out.println(" Result is :"+c ); } }
before call before expression... after expression Result is :4 after call program end
class demo { public static void main(String args[]) { System.out.println(" before call" ); test(8,0); System.out.println(" after call" ); System.out.println(" program end" ); } public static void test( int a , int b ) { int c=0; try { System.out.println("before expression..."); c= a/b; System.out.println("after expression"); } catch(ArithmeticException er) { System.out.println("error message : "+er); c=1; } System.out.println(" Result is :"+c ); } }
Before call Before expression Error message: Aithmetic Exception . . . Result is 1 After call Program end